// 返回格式实体类
package com.chenlehao.pojo;

public class result {
    /* 定于一个统一响应结果的实体类 */
    // 返回验证码 code = 1 则说明返回成功
    private int code;
    // 返回描述字符串 msg = "ok" 则说明返回成功
    private String msg;
    // 响应数据
    private Object data;

    public result() {
    }

    public result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 成功静态方法(有返回值)
    public static result success(Object data) {
        return new result(1, "ok", data);
    }

    // 成功静态方法(无返回值)
    public static result success() {
        return new result(1, "ok", null);
    }

    // 错误静态方法(无错误提示)
    public static result error() {
        return new result(99, "");
    }

    // 错误静态方法(有错误提示)
    public static result error(String msg) {
        return new result(99, msg);
    }

    // 错误静态方法(有错误码和错误提示)
    public static result error(int code, String msg) {
        return new result(code, msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
